package com.haolijun.eecms.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.haolijun.eecms.dao.TbNoticeCommentDao;
import com.haolijun.eecms.entity.TbNoticeComment;
import com.haolijun.eecms.service.NoticeCommentService;
import com.haolijun.eecms.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @ClassName NoticeCommentServiceImpl
 * @Description TODO
 * @Author hljstart
 * @Date 2023/3/11 21:27
 * @Version 1.0
 */
@Service
@Slf4j
public class NoticeCommentServiceImpl implements NoticeCommentService {
    @Autowired
    private TbNoticeCommentDao noticeCommentDao;

    @Autowired
    private NoticeService noticeService;

    @Transactional
    @Override
    public int insert(TbNoticeComment noticeComment){
        int userId = StpUtil.getLoginIdAsInt();
        log.info("用户的id", StpUtil.getLoginIdAsInt());
        noticeComment.setUserId(userId);
        noticeComment.setCreateTime(new Date());
        int rows = noticeCommentDao.insert(noticeComment);
        noticeService.updateCommentCount();
        return rows;
    }

    @Override
    public int delete(Integer nid) {
        int rows = noticeCommentDao.delete(nid);
        return rows;
    }
}
